<?php
defined('BASEPATH') OR exit('No direct script access allowed');

use Core\AdminController;
use Models\Item;
use Models\PurchaseRecord;
use Models\Order;

class IndexController extends AdminController {

	public function __construct(){
		parent::__construct();
	}

	public function index(){
		// 显示库存不足的商品
		$danger_stocks = Item::select('items.title,items.en_title,items.stock,products.id,products.title as p_title,products.en_title as p_en_title')->where('items.stock<=items.danger_stock')->join('products','products.id = items.product_id')->limit(6)->get();

		// 过期的商品列表
		$items = PurchaseRecord::select('purchase_records.id,purchase_records.stock,purchase_records.expire,purchase_records.product_id,purchase_records.item_id,items.title as item_title,items.en_title as item_en_title,products.title as p_title,products.en_title as p_en_title')
								->join('items', 'items.id=purchase_records.item_id')
								->join('products','products.id=purchase_records.product_id')
								->where('purchase_records.stock >',0)
								->where('purchase_records.expire <',time())
								->limit(6)->get();

		// 显示支付未处理的订单
		$orders = Order::where('type=1')->limit(6)->get();
		$this->load->view('admin/index', [
			'danger_stocks' => $danger_stocks,
			'items' => $items,
			'orders' => $orders,
		]);
	}


}